package date2_25;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*1.准备54张牌完成数组与纸牌的映射关系，
 		使用双列map集合，完成一个数字与字符串纸牌的对应关系
 		0--大王 1--小王 2--♠2 3--♣2 4--♦2....
2.洗牌
3.发牌
1人17张，轮流摸牌
4.看牌*/
public class DouDiZhu {
	public static void main(String[] args) {
		//定义集合来存储54张牌
		ArrayList<String> poker=new ArrayList<>();
		//定义两个数组，一个数组存储花色，一个数组存储的序号
		String[] colors={"♠","♣","♦","♥"};
		String[] numbers={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
		poker.add("大王");
		poker.add("小王");
		//组装52张牌
		for(String number:numbers){
			for(String color:colors){
				poker.add(color+number);
			}
		}
		System.out.println(poker);
		// 洗牌
		Collections.shuffle(poker);
		System.out.println(poker);
		//发牌
		Player p1=new Player("老王");
		Player p2=new Player("老李");
		Player p3=new Player("老六");
		ArrayList<String> dipai=new ArrayList<>();
		//遍历集合，获取每一张牌
		//使用poker集合轮流发牌  索引%3
		for(int i=0;i<poker.size();i++){
			String p = poker.get(i);
			//轮流发牌
			if(i>=51){
				//底牌
				dipai.add(p);
			}else if(i%3==0){
				p1.getPoker().add(p);
			}else if(i%3==1){
				p2.getPoker().add(p);
			}else if(i%3==2){
				p3.getPoker().add(p);
			}
		}
		 // 对牌进行排序
        sortPoker(p1.getPoker());
        sortPoker(p2.getPoker());
        sortPoker(p3.getPoker());
		//看牌
		System.out.println(p1.getName()+":"+p1.getPoker());
		System.out.println(p2.getName()+":"+p2.getPoker());
		System.out.println(p3.getName()+":"+p3.getPoker());
		System.out.println(dipai);
	
	}
	private static void sortPoker(List<String> poker) {
        poker.sort(new Comparator<String>() {
            public int compare(String o1, String o2) {
                return valueOfCard(o1) - valueOfCard(o2);
            }

            int valueOfCard(String card) {
                String number = card.substring(1);
                switch(number) {
                    case "A": return 1;
                    case "2": return 2;
                    case "3": return 3;
                    case "4": return 4;
                    case "5": return 5;
                    case "6": return 6;
                    case "7": return 7;
                    case "8": return 8;
                    case "9": return 9;
                    case "10": return 10;
                    case "J": return 11;
                    case "Q": return 12;
                    case "K": return 13;
                    case "小王": return 14;
                    case "大王": return 15;
                    default: return 0;
                }
            }
        });
    }
}
